/**
 * 目标：引入工具函数使用
 */
import { checkUserName, checkPassWord } from 'MyUtils/check.js'
// import { checkUserName, checkPassWord } from './utils/check.js'

import './css/index.css'
import './less/index.less'

import axios from 'axios'

import img from  './assets/yao.jpg'

document.querySelector('.imgBox').src = img
// const unameResult = checkUserName('itheima007')
// const pwdResult = checkPassWord('7654321')
// console.log(unameResult, pwdResult)

document.querySelector('.login-btn').addEventListener('click', () => {
  const username = document.querySelector('.username').value
  const password = document.querySelector('.password').value

  if (!checkUserName(username)) {
    alert('用户名长度要大于等于8位')
    return
  } else if (!checkPassWord(password)) {
    alert('密码长度要求大于等于6位')
    return
  }

  axios({
    url:'http://hmajax.itheima.net/api/register',
    method:'post',
    data:{
      username,
      password
    }
  }).then(result => {
    alert(result.data.message)
  }).catch(error => {
    alert(error.response.data.message)
  })
})


/**
 * 目标：让 Webpack + Babel 编译降级 JS 语法
 */
const arr = [1, 2, 3]
const result = arr.map(val => val + 1)
console.log(result)